package br.com.tarlis.persistent.server.mysql;

import java.util.HashMap;

import br.com.tarlis.accesscontrol.client.model.User;
import br.com.tarlis.persistent.server.DatabaseConnection;
import br.com.tarlis.persistent.server.PoolManager;

public class MySQLPoolManager implements PoolManager {

	private MySQLPoolManager() {
		
	}
	
	private static final HashMap<User, DatabaseConnection<?>> pool = 
				new HashMap<User, DatabaseConnection<?>>();

	public DatabaseConnection<?> getConnection(User key) {
		return pool.get(key);
	}

	public boolean isEmpty() {
		return pool.isEmpty();
	}

	public DatabaseConnection<?> putConnection(User key, DatabaseConnection<?> value) {
		return pool.put(key, value);
	}

	public DatabaseConnection<?> removeConnection(User key) {
		getConnection(key).close();		
		return pool.remove(key);
	}

	public int size() {
		return pool.size();
	}
	
}
